package cn.wolfcode.web;

import cn.wolfcode.config.WebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
public class SendMsgController {

    @Autowired
    private WebSocketServer webSocketServer;
    //向指定的websocket客户端发送数据
    @RequestMapping("/sendtoclient")
    public String sendMsg(String msg,String token) throws IOException {
        WebSocketServer webSocketServer = WebSocketServer.clients.get(token);//通过token获取指定的自定义服务端实例
        webSocketServer.getSession().getBasicRemote().sendText("");//通过这个实例进而与指定客户端通信
        return "向客户端发送消息成功";
    }
}
